Ext.ns('SearchSort');
SearchSort.ChartPanel = Ext.extend(Ext.Panel, {
	//renderTo: 'binding-example',
	frame: true,
	title: 'SearchSort List',
	//width: 540,
	//height: 400,
	layout: 'border',
	initComponent :function(){
	   this.items = [
	     	   		{
	    				id: 'urlPanel',
	    				region: 'north',
	    				bodyStyle: {
	    					background: '#ffffff',
	    					padding: '7px'
	    				},
	    				html: '<a>url........</a>'
	    			},
	    			SearchSort.DataPanel
	    		],
	   Ext.Panel.superclass.initComponent.apply(this, arguments);  
	   Ext.getCmp("HelpMsg").setValue("Sort CBBC request:" +
	   "-1,5,60,2,1,37,D,0,40\n fieldID=1，code=34   40条数据\n\n" +
	   "Sort INDEX request:" +
	   "-1,3,65,2,HSIS.HSI，1,A,0,50\n\n" +
	   "Sort INDUSTRY request:" +
	   "-1,2,76,2,5001,1,A,0,50\n\n" +
	   "Sort STOCK request:" +
	   "-1,6,47,2,,194,D,0,10\n\n" +
	   "Sort WAR request:" +
	   "-1,4,45,1,HSIS.HSI,36,D,0,50");
	}
});
SearchSort.tbar = ['reqType: ',' '
                   ,new Ext.form.ComboBox({
                  	  id:'reqType',
                  	  hiddenName:'reqType',
                        store: [['5','CBBC'],['3','INDEX'],['2','INDUSTRY'],['6','STOCK'],['4','WAR']],
                        typeAhead: true,
                        forceSelection: true,
                        triggerAction: 'all',
                        valueField:'value',
                        displayField :'key',
                        width:120,
                        emptyText:'Select a type...',
                        selectOnFocus:true
                    }), 'Field ID: ','',
        		   {
        			   id:'fieldid',
        			xtype:'field',
        				width:60,
        				listeners : {  
                            specialKey : function(field, e) {  
                                if (e.getKey() == Ext.EventObject.ENTER) {
                                	SearchSort.requestHandler();   
                                }  
                            } 
        			}
               }," "," ",
               'Code: ','',
    		   {
    			   id:'code',
    			xtype:'field',
    				width:60,
    				listeners : {  
                        specialKey : function(field, e) {  
                            if (e.getKey() == Ext.EventObject.ENTER) {
                            	SearchSort.requestHandler();   
                            }  
                        } 
    				}
    		   },'Sort: ',' '
               ,new Ext.form.ComboBox({
             	  id:'SortID',
             	  hiddenName:'SortID',
                   store: [['A','ASC'],['D','DESC']],
                   typeAhead: true,
                   forceSelection: true,
                   triggerAction: 'all',
                   valueField:'value',
                   displayField :'key',
                   width:120,
                   emptyText:'Select a type...',
                   selectOnFocus:true
               }),'from: ','',
    		   {
    			   id:'from',
    			xtype:'field',
    				width:60,
    				listeners : {  
                        specialKey : function(field, e) {  
                            if (e.getKey() == Ext.EventObject.ENTER) {
                            	SearchSort.requestHandler();   
                            }  
                        } 
    			}
    				
    		   },'to: ','',
    		   {
    			   id:'to',
    			xtype:'field',
    				width:60,
    				listeners : {  
                        specialKey : function(field, e) {  
                            if (e.getKey() == Ext.EventObject.ENTER) {
                            	SearchSort.requestHandler();   
                            }  
                        } 
    				}
    		   },
               " "," "
        		    ,'-',
                  {
                  	xtype:'button',
                  	text:'Search',
                  	handler: function(){
    			   SearchSort.requestHandler();
        		    }
                  }
        ];
SearchSort.DataPanel =  new Ext.Panel({	
	//renderTo: document.body,
	region: 'center',
	//autoHeight: true,
    //autoWidth:true,
    autoScroll: true,
	
	title : 'Search Quote',
	tbar:SearchSort.tbar,
	layout:"border", 
	items:[
	{	id:'headerfield',
		xtype:"field",
		region:"north",
		fieldLabel:"headerfield:",
		name:"headerfield",
		value:"request......",
		height:25,
		readOnly : true,
		width:800},
		{	id:'resultMsg',
			xtype:"textarea",
			region:"center",
            fieldLabel:"result:",
            name:"resultMsg",
            height:450,
			readOnly : true,
			width:800},
			{	id:'HelpMsg',
				xtype:"textarea",
	            fieldLabel:"result:",
	            region:"east",
	            name:"HelpMsg",
	            height:450,
				readOnly : true,
				width:200}
	]
});
SearchSort.requestHandler = function requestHandler() {	
	var urls =contextURL+'SearchSortServlet';
	var reqType =Ext.getCmp('reqType').getValue();
	var fieldid = Ext.get("fieldid").dom.value;
	var code = Ext.get("code").dom.value;
	var SortID = Ext.getCmp('SortID').getValue();
	var from = Ext.getCmp('from').getValue();
	var to = Ext.getCmp('to').getValue();
	if(reqType==""){
		 Ext.Msg.alert("提示信息","reqType is not null!"); 
		return;
	}
	if(fieldid==""){
		 Ext.Msg.alert("提示信息","fieldid is not null!"); 
		return;
	}
	if(code==""){
		 Ext.Msg.alert("提示信息","code is not null!"); 
		return;
	}
	if(SortID==""){
		 Ext.Msg.alert("提示信息","Sort Type is not null!"); 
		return;
	}
	if(from==""){
		 Ext.Msg.alert("提示信息","from is not null!"); 
		return;
	}
	if(to==""){
		 Ext.Msg.alert("提示信息","to is not null!"); 
		return;
	}
	urls = urls+"?fieldid="+fieldid+"&code="+code+"&reqType="+reqType+"&sortType="+SortID+"&from="+from+"&to="+to;
	 
	Ext.getDom("urlPanel").innerHTML = "<a href='" + urls + "' target='_blank'>" + urls + "</a>";
	var mk = new Ext.LoadMask(Ext.getBody(), {
		msg: '正在更新数据，请稍候！'
	});
	mk.show(); //显示
	
	
	Ext.Ajax.request( {
		url : urls,
		method : "GET",
		success : function(result, request) {
			var jsonResult = Ext.util.JSON.decode(result.responseText);
			if (jsonResult.resultCode=='0'){				
				Ext.getCmp("headerfield").setValue("request:"+jsonResult.reqStr);
				Ext.getCmp("resultMsg").setValue("Hearder:\n"+jsonResult.header+"\nContent:\n"+jsonResult.content);
			}
			else
			{
				Ext.Msg.alert('操作提示','结果为空'); 
			}
			mk.hide();
			Ext.getCmp("fieldid").focus();
		},
		failure : function(result, request) {
			Ext.MessageBox.alert('访问失败', '失败了就没好说的了  (*^__^*) 嘻嘻……: ');
			mk.hide();
			Ext.getCmp("fieldid").focus();
		}
			// ,scope : this
			// params: param
		});
	Ext.getCmp("fieldid").focus();
};
Ext.onReady(function(){
	//War.ChartGrid.render(document.body);
	new SearchSort.ChartPanel({
		frame: true,
		layout:'border',
		renderTo: 'grid-example',
		height : 600,
		width : 1000
	});
});
	
